import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from './modules/user/user.module';
import { UploadModule } from './modules/upload/upload.module';
import { RoleModule } from './modules/role/role.module';
import { MenuModule } from './modules/menu/menu.module';
import { RoleMenuModule } from './modules/role-menu/role-menu.module';
import { UserRoleModule } from './modules/user-role/user-role.module';
import { APP_GUARD } from '@nestjs/core';
import { RolesGuard } from './common/roles.guard';
import { RedisModule } from './redis/redis.module';
import { BooksModule } from './modules/books/books.module';
import { CategoryModule } from './modules/category/category.module';
import { BorrowModule } from './modules/borrow/borrow.module';
const mysqlConfigModule = TypeOrmModule.forRoot({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: '123456',
  database: 'books',
  // entities: [__dirname, '/**/*.entity{.ts,.js}'],
  autoLoadEntities: true,
  synchronize: true,
})
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      envFilePath: ['.cos.env']
    }),
    RedisModule.register('db0', {
      host: 'localhost',
      port: 6379,
      password: '',
      db: 0
    }),
    UserModule, 
    mysqlConfigModule, 
    UploadModule, RoleModule, MenuModule, RoleMenuModule, UserRoleModule,
    BooksModule, CategoryModule, BorrowModule
],
providers: [
  {
    provide: APP_GUARD,
    useClass: RolesGuard
  },
],
})
export class AppModule {}
